Skip to content

Keep discarded reductions out of parser tables - #870

Merged
ydah merged 1 commit into
masterfrom
fix/respect-selected-reduction-lookaheads
Nov 12, 2026
Merged

ydah merged 1 commit into
masterfrom
fix/respect-selected-reduction-lookaheads

Conversation

@ydah

@ydah ydah commented Nov 11, 2026

Copy link
Copy Markdown
Member

Context#compute_yydefact builds reduce actions from the original lookaheads, including tokens excluded during precedence resolution. If one reduction loses to a shift and another reduction removes that shift, the discarded reduction can be written back into the table and take priority over the selected one.

Use selected_look_ahead when writing reduce actions so the generated table preserves those precedence decisions.

For example:

%precedence LOW
%precedence 'b'
%precedence HIGH
%%
start: 'a' empty 'b' 'x' | direct 'b' 'y'
     | 'a' 'b' 'z' | 'a' empty 'c';
empty: %empty %prec LOW;
direct: 'a' %prec HIGH;

Both LALR and IELR parsers previously accepted abx and rejected aby. They now reject abx and accept aby, matching Bison 3.8.2. Add regression tests for the generated tables and parsers, including ac to check that the empty rule still reduces on tokens unaffected by precedence resolution.

@ydah
ydah merged commit e78f40a into master Nov 12, 2026
83 of 89 checks passed
@ydah
ydah deleted the fix/respect-selected-reduction-lookaheads branch November 12, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant